function formatTime(date) {
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  const hour = date.getHours();
  const minute = date.getMinutes();
  const second = date.getSeconds();


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

// 内置手机号正则字符串
const innerPhoneReg = '^1(?:3\\d|4[4-9]|5[0-35-9]|6[67]|7[0-8]|8\\d|9\\d)\\d{8}$';

/**
 * 手机号正则校验
 * @param phone 手机号
 * @returns true - 校验通过 false - 校验失败
 */
const phoneRegCheck = (phone) => {
  const phoneRegExp = new RegExp(innerPhoneReg);
  return phoneRegExp.test(phone);
};

const conversionAmount = (amount, bipolar = true) =>{
  if(amount.charAt(0) === "¥"){
    amount = amount.slice(1); // 去除第一个字符
  }
  amount = amount.replace(",", "");
  if(!bipolar) {
    amount = '-' + amount;
  }
  return parseFloat(amount);
}


module.exports = {
  formatTime,
  phoneRegCheck,
  conversionAmount
}
